﻿using GalaSoft.MvvmLight.Messaging;
using JiveMessenger.Models;
using JiveMessenger.User;
using JiveMessenger.ViewModels;
using System.Windows;

namespace JiveMessenger.Views
{
    /// <summary>
    /// Description for MangeGroupWindow.
    /// </summary>
    public partial class ManageGroupWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the MangeGroupWindow class.
        /// </summary>
        public ManageGroupWindow(IChatGroup group, IClient currentClient)
        {
            InitializeComponent();
            this.DataContext = new ViewModelManageGroup(currentClient, group);

            Messenger.Default.Register<NotificationMessage>(this, msg =>
            {
                if (msg.Notification == "CloseWindow" && (msg.Sender == this.DataContext))
                    this.Close();
            });
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ((ViewModelManageGroup)this.DataContext).Cleanup();
            this.ManageGroupControl.Dispose();
        }
    }
}